package com.lizhi.menu.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lizhi.menu.Dto.CommodityTypeDto;
import com.lizhi.menu.common.response.Result;
import com.lizhi.menu.domain.CommodityType;
import com.lizhi.menu.service.ICommodityTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 商品类型Controller
 *
 * @author lizhi
 * @date 2023-05-18
 */
@RestController
@RequestMapping("/system/commoditytype")
@RequiredArgsConstructor
@Api(tags = "商品类型管理")
public class CommodityTypeController {
    private final ICommodityTypeService commodityTypeService;

    /**
     * 查询商品类型列表
     */
    @GetMapping("/list")
    @ApiOperation("查询商品类型列表")
    public Result<Page<CommodityType>> list(CommodityTypeDto commodityType) {
        return Result.ok(commodityTypeService.selectCommodityTypeList(commodityType));
    }

    /**
     * 获取商品类型详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取商品类型详细信息")
    public Result<CommodityType> getInfo(@PathVariable("id") String id) {
        return Result.ok(commodityTypeService.selectCommodityTypeById(id));
    }

    /**
     * 新增商品类型
     */
    @PostMapping
    @ApiOperation("新增商品类型")
    public Result<Void> add(@RequestBody CommodityType commodityType) {
        commodityTypeService.insertCommodityType(commodityType);
        return Result.ok();
    }

    /**
     * 修改商品类型
     */
    @PutMapping
    @ApiOperation("修改商品类型")
    public Result<Void> edit(@RequestBody CommodityType commodityType) {
        commodityTypeService.updateCommodityType(commodityType);
        return Result.ok();
    }

    /**
     * 删除商品类型
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除商品类型")
    public Result<Void> remove(@PathVariable String id) {
        commodityTypeService.remove(id);
        return Result.ok();
    }
}
